import 'package:flutter/material.dart';
import 'package:hibrid_flutter/main.dart';
import 'package:image_picker/image_picker.dart';

import 'dir_image.dart';

class PhotoPicker extends StatelessWidget {
  final String url;
  final double? width;
  final double? height;

  PhotoPicker(this.url, {this.width, this.height});

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: <Widget>[
        GestureDetector(
          onTap: () {
            myRoute.popRoute();
          },
          child: Align(
            alignment: Alignment.center,
            child: DirImage(
              url: url,
              width: width,
              height: height,
            ),
          ),
        ),
        GestureDetector(
          onTap: () async{
            print('photoPicker - ImagePicker onTap');
            final pickedFile = await ImagePicker().pickImage(source: ImageSource.gallery);
            var res = pickedFile?.path;
            print('photoPicker - ImagePicker ${res}');
            if (res != null) {
              myRoute.popRoute(params: res);
            }
          },
          child: Padding(
            padding: const EdgeInsets.only(bottom: 80),
            child: Align(
              alignment: Alignment.bottomCenter,
              child: Container(
                width: 120,
                height: 40,
                alignment: Alignment.center,
                color: Colors.white38,
                child: const Text(
                  '更换背景',
                  style: TextStyle(fontSize: 16, color: Colors.white, decoration: TextDecoration.none),
                ),
              ),
            ),
          ),
        ),
      ],
    );
  }
}
